package com.soft.sitegenerator.business.hibernate;

import java.util.Collection;

import com.soft.sitegenerator.dao.HibernateDAO;
import com.soft.sitegenerator.exceptions.ObjectNotFoundException;

public class Profile {
	private Long id;

	private String name;

	private Role role;

	private HibernateDAO hibernateDAOHib;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	// HIBERNATE DAO
	public HibernateDAO getHibernateDAOHib() {
		return hibernateDAOHib;
	}

	public void setHibernateDAOHib(HibernateDAO hibernateDAOHib) {
		this.hibernateDAOHib = hibernateDAOHib;
	}

	public void load() throws ObjectNotFoundException {
		hibernateDAOHib.load(this, this.id);
	}

	public void save() {
		hibernateDAOHib.save(this);
	}

	public void update() {
		hibernateDAOHib.update(this);
	}

	public void delete() {
		hibernateDAOHib.delete(this);
	}

	public boolean exist() {
		try {
			hibernateDAOHib.exist(this, this.id);
		} catch (ObjectNotFoundException e) {
			return false;
		}
		return true;
	}

	public Collection findAll() {
		return hibernateDAOHib.find("from Profile order by name");
	}

}
